package cn.jsj.cxsys.controller;

import org.springframework.stereotype.*;
import org.springframework.beans.factory.annotation.*;
import cn.jsj.cxsys.service.*;
import java.util.*;
import cn.jsj.cxsys.pojo.*;
import org.springframework.web.bind.annotation.*;
import cn.jsj.cxsys.controller.packageClass.*;

@ResponseBody
@CrossOrigin
@Controller
public class LabController
{
    @Autowired
    private UserService userService;
    @Autowired
    private TeacherLabService teacherLabService;
    @Autowired
    private StudentLabService studentLabService;

    @RequestMapping(value = { "labList" }, method = { RequestMethod.POST }, params = { "account", "password" })
    public User_LabList userGetLabs(@RequestParam("account") final String account, @RequestParam("password") final String password) {
        final User user = this.userService.getUserByAccount(account, password);
        if (user == null) {
            return null;
        }
        final User_LabList cover = User_LabList.getUser_LabListClass();
        cover.setLabList(this.studentLabService.getLabList());
        cover.setPrivelageList(this.studentLabService.getStudentAppledLabID(user));
        return cover;
    }

    @RequestMapping(value = { "changeLabName" }, method = { RequestMethod.POST }, params = { "teacherAccount", "password", "labID", "labName" })
    public String changeLabName(@RequestParam("teacherAccount") final String teacherAccount, @RequestParam("password") final String password, @RequestParam("labID") final Integer labID, @RequestParam("labName") final String labName) {
        return this.teacherLabService.changeNameOfOneLab(teacherAccount, password, labID, labName);
    }

    @RequestMapping(value = { "superGetLab" }, method = { RequestMethod.POST })
    public List<Lab> superGetLabs() {
        return (List<Lab>)this.studentLabService.getLabList();
    }

    @RequestMapping(value = { "Apply" }, method = { RequestMethod.POST })
    public String applyLab(@RequestBody final Student_ApplyLab para) {
        if (para == null) {
            return "paramLess";
        }
        return this.studentLabService.ApplyLab(para.getLabMessage(), para.getStudent());
    }

    @RequestMapping(value = { "CreatLab" }, method = { RequestMethod.POST })
    public String creatLab(@RequestBody final Teacher_CreatLab tc) {
        if (tc == null) {
            return "paramLess";
        }
        return this.teacherLabService.creatOneLab(tc.getLab(), tc.getTeacher());
    }

    @RequestMapping(value = { "responseApply" }, method = { RequestMethod.POST })
    public String responseApply(@RequestBody final Teacher_ResponseLab para) {
        if (para == null) {
            return "paramLess";
        }
        return this.teacherLabService.judgeStudentApply(para.getTeacher(), para.getLabMessage());
    }

    @RequestMapping(value = { "teacherGetStudentInformation" }, method = { RequestMethod.POST })
    public User TeacherGetUserInformation(@RequestBody final User_INT ui) {
        if (ui == null) {
            return null;
        }
        return this.teacherLabService.getStudentInformationOfApplyLab(ui.getUser(), ui.getId());
    }

    @RequestMapping(value = { "teacherOrLaderGetUsersInLab" }, method = { RequestMethod.POST })
    public List<User> getUsersInLabNow(@RequestBody final User_INT ui) {
        if (ui == null) {
            return null;
        }
        return (List<User>)this.teacherLabService.getStudentsInLabAtThisTime(ui.getUser(), ui.getId());
    }

    @RequestMapping(value = { "sigInLab" }, method = { RequestMethod.POST })
    public String StudentSignInLab(@RequestBody final User_INT ui) {
        if (ui == null) {
            return null;
        }
        return this.studentLabService.studentSigInLab(ui.getUser(), ui.getId());
    }

    @RequestMapping(value = { "signOutLab" }, method = { RequestMethod.POST })
    public String StudentSignOutLab(@RequestBody final User_String us) {
        if (us == null) {
            return "paramLess";
        }
        return this.studentLabService.studentSignOutLab(us.getStudent(), us.getInformation());
    }

    @RequestMapping(value = { "changeDescription" }, method = { RequestMethod.POST })
    public String changeDescription(@RequestBody final User_INT_Str ui) {
        if (ui == null) {
            return "paramLess";
        }
        return this.teacherLabService.changeDescriptionOfOneLab(ui.getUser(), ui.getId(), ui.getStr());
    }
}
